package whf.framework.security.web;

import whf.framework.entity.AbstractEntity;
import whf.framework.security.entity.Dept;
import whf.framework.security.service.DeptServiceImp;
import whf.framework.web.struts.WebData;
import whf.framework.web.struts.WebDispatchAction;
import whf.framework.web.struts.WebForward;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2006-07-06
 */
public class DeptAction extends WebDispatchAction {

	@Override
	public WebForward create(AbstractEntity webEntity, WebData data) throws Exception {
		WebForward f = super.create(webEntity, data);
		Dept parent = ((Dept)webEntity).getParent();
		if(parent != null){
			data.setAttribute("parentId", parent.getId());
		}
		return f;
	}

	@Override
	public WebForward prepareCreate(AbstractEntity webEntity, WebData data) throws Exception {
		long parentId = data.getLongParameter("parentId", 0);
		if(parentId > 0){
			Dept parent = DeptServiceImp.getDeptService().findByPrimaryKey(parentId);
			((Dept)webEntity).setParent(parent);
		}
		return super.prepareCreate(webEntity, data);
	}

	@Override
	public WebForward update(AbstractEntity entity, WebData data) throws Exception {
		WebForward f = super.update(entity, data);
		Dept parent = ((Dept)entity).getParent();
		if(parent != null){
			data.setAttribute("parentId", parent.getId());
		}
		return f;
	}
} 